package com.util;


import com.constant.CommonConstant;
import com.dto.ResponseDto;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author :ex_1101873X0
 * @description: 响应工具类
 * @create date: 2020-1-2 11:43
 */
public class ResponseUtil {

    private ResponseUtil() {
    }

    public static <T> ResponseDto success(T data) {
        return new ResponseDto<T>(CommonConstant.SUCCESS_CODE, data, CommonConstant.API_RESULT_SUCCESS_MSG);
    }

    public static <T> ResponseDto successForMsg(String msg) {
        return new ResponseDto<T>(CommonConstant.SUCCESS_CODE, null, msg);
    }

    public static <T> ResponseDto successList(List<T> list) {
        Map<String, List<T>> dataMap=new HashMap();
        dataMap.put("list",list);
        return new ResponseDto(CommonConstant.SUCCESS_CODE, dataMap, CommonConstant.API_RESULT_SUCCESS_MSG);
    }

    public static ResponseDto success() {
        return new ResponseDto(CommonConstant.SUCCESS_CODE, null, CommonConstant.API_RESULT_SUCCESS_MSG);
    }

    public static ResponseDto fail(String msg) {
        return new ResponseDto(CommonConstant.FAILED_CODE, null, msg);
    }

    public static ResponseDto fail() {
        return new ResponseDto(CommonConstant.FAILED_CODE, null, CommonConstant.API_RESULT_FAIL_MSG);
    }


}
